local skel = fk.CreateSkill {
  name = "emo__qiyao",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["emo__qiyao"] = "启耀",
  [":emo__qiyao"] = "限定技，出牌阶段，你可以扣减一点体力上限，从时机为“游戏开始时”的随机四个技能中选择一个，获得并触发此技能。",

  ["#emo__qiyao-choice"] = "启耀：选择一个技能并获得",
  ["#emo__qiyao"] = "启耀：扣减1点体力上限，获得一个“游戏开始时”的技能并发动！",

  ["$emo__qiyao1"] = "此刻正是群星闪耀之时",
  ["$emo__qiyao2"] = "请星星指引我",
}

skel:addEffect("active", {
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  prompt = "#emo__qiyao",
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:changeMaxHp(player, -1)
    if player.dead then return end
    local ban_skills = {}
    local skills = {}
    for _, p in ipairs(room.players) do
      table.insertTableIfNeed(ban_skills, p:getSkillNameList())
    end
    for _, general_name in ipairs(room.general_pile) do
      local general = Fk.generals[general_name]
      for _, skill_name in ipairs(general:getSkillNameList()) do
        local skill = Fk.skills[skill_name]
        if not player:hasSkill(skill, true) and skill:isInstanceOf(TriggerSkill) and skill.event == fk.GameStart
        and not table.contains(ban_skills, skill.name) then
          local str = Fk:translate(":"..skill_name)
          if string.find(str, "游戏开始时") then
            table.insertIfNeed(skills, skill_name)
          end
        end
      end
    end
    if #skills == 0 then return end
    local choice = room:askToChoice(player, {
      choices = table.random(skills, 4), skill_name = skel.name, detailed = true, prompt = "#emo__qiyao",
    })
    local skill = Fk.skills[choice]
    if not skill then return end
    room:handleAddLoseSkills(player, skill.name)
    local all_skills = table.connect({skill}, skill.related_skills) ---@type TriggerSkill[]
    local skillList = table.filter(all_skills, function (s)
      return s:isInstanceOf(TriggerSkill) and s.event == fk.GameStart
    end)
    local event_data = {}
    local event_obj = fk.GameStart:new(room, nil, event_data)
    for _, s in ipairs(skillList) do
      if player.dead then break end
      if s:triggerable(event_obj, nil, player, event_data) then
        s:trigger(event_obj, nil, player, event_data)
      end
    end
  end,
})

return skel
